package com.lesson01;

//测试类什么时候会初始化
public class Test06 {
    static {
        System.out.println("Main被加载");
    }

    public static void main(String[] args) throws ClassNotFoundException {
        //1.主动引用
        //Son son = new Son();
        //2.反射也会产生主动引用
        //Class.forName("com.lesson01.Son");
        //3.不会产生主动引用,不会使用子类加载
        //System.out.println(Son.b);
        //Son[] array = new Son[5];//只有Main类加载
        //调用,子类中的常量，只用main类加载
        System.out.println(Son.M);
    }
}
class Father{
    static int b = 2;
    static {
        System.out.println("父类被加载");
    }
}
class Son extends Father{
    static {
        System.out.println("子类被加载");
        m=300;
    }
    static int m=100;
    static final int M=1;
}